/*
This file is part of Arcadeflex.

Arcadeflex is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Arcadeflex is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Arcadeflex.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * ported to v0.28
 * ported to v0.27
 *
 * NOTES: romsets are from v0.36 roms
 *        
 *
 */

package drivers;

import static arcadeflex.libc.*;
import static mame.commonH.*;
import static mame.cpuintrf.*;
import static mame.driverH.*;
import static mame.mame.*;
import static mame.osdependH.*;
import static sndhrdw._8910intf.*;
import static sndhrdw.capcom.*;
import static sndhrdw.generic.*;
import static machine._1942.*;
import static vidhrdw.generic.*;
import static vidhrdw._1942.*;
import static mame.inptport.*;

public class _1942
{



	static MemoryReadAddress readmem[] =
	{
		new MemoryReadAddress( 0x0000, 0x7fff, MRA_ROM ),
		new MemoryReadAddress( 0x8000, 0xbfff, c1942_bankedrom_r ),
		new MemoryReadAddress( 0xc000, 0xc000, input_port_0_r ),	/* IN0 */
		new MemoryReadAddress( 0xc001, 0xc001, input_port_1_r ),	/* IN1 */
		new MemoryReadAddress( 0xc002, 0xc002, input_port_2_r ),	/* IN2 */
		new MemoryReadAddress( 0xc003, 0xc003, input_port_3_r ),	/* DSW0 */
		new MemoryReadAddress( 0xc004, 0xc004, input_port_4_r ),	/* DSW1 */
		new MemoryReadAddress( 0xd000, 0xdbff, MRA_RAM ),
		new MemoryReadAddress( 0xe000, 0xefff, MRA_RAM ),
		new MemoryReadAddress( -1 )	/* end of table */
	};
	
	static MemoryWriteAddress writemem[] =
	{
		new MemoryWriteAddress( 0x0000, 0xbfff, MWA_ROM ),
		new MemoryWriteAddress( 0xc800, 0xc800, sound_command_w ),
		new MemoryWriteAddress( 0xc802, 0xc803, MWA_RAM, c1942_scroll ),
		new MemoryWriteAddress( 0xc804, 0xc804, c1942_flipscreen_w ),
		new MemoryWriteAddress( 0xc805, 0xc805, c1942_palette_bank_w, c1942_palette_bank ),
		new MemoryWriteAddress( 0xc806, 0xc806, c1942_bankswitch_w ),
		new MemoryWriteAddress( 0xcc00, 0xcc7f, MWA_RAM, spriteram, spriteram_size ),
		new MemoryWriteAddress( 0xd000, 0xd3ff, videoram_w, videoram, videoram_size ),
		new MemoryWriteAddress( 0xd400, 0xd7ff, colorram_w, colorram ),
		new MemoryWriteAddress( 0xd800, 0xdbff, c1942_background_w, c1942_backgroundram, c1942_backgroundram_size ),
		new MemoryWriteAddress( 0xe000, 0xefff, MWA_RAM ),
		new MemoryWriteAddress( -1 )	/* end of table */
	};
	
	
	
	static MemoryReadAddress sound_readmem[] =
	{
		new MemoryReadAddress( 0x0000, 0x3fff, MRA_ROM ),
		new MemoryReadAddress( 0x4000, 0x47ff, MRA_RAM ),
		new MemoryReadAddress( 0x6000, 0x6000, sound_command_latch_r ),
		new MemoryReadAddress( -1 )	/* end of table */
	};
	
	static MemoryWriteAddress sound_writemem[] =
	{
		new MemoryWriteAddress( 0x0000, 0x3fff, MWA_ROM ),
		new MemoryWriteAddress( 0x4000, 0x47ff, MWA_RAM ),
		new MemoryWriteAddress( 0x8000, 0x8000, AY8910_control_port_0_w ),
		new MemoryWriteAddress( 0x8001, 0x8001, AY8910_write_port_0_w ),
		new MemoryWriteAddress( 0xc000, 0xc000, AY8910_control_port_1_w ),
		new MemoryWriteAddress( 0xc001, 0xc001, AY8910_write_port_1_w ),
		new MemoryWriteAddress( -1 )	/* end of table */
	};
	
	
	
	static InputPortPtr input_ports = new InputPortPtr(){ public void handler() { 
		PORT_START(); 	/* IN0 */
		PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_START1 );
		PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_START2 );
		PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_UNKNOWN );/* probably unused */
		PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_UNKNOWN );/* probably unused */
		PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_COIN3 );
		PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN );/* probably unused */
		PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_COIN2 );
		PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_COIN1 );
	
		PORT_START(); 	/* IN1 */
		PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY );
		PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_8WAY );
		PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_8WAY );
		PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_8WAY );
		PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 );
		PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 );
		PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN );/* probably unused */
		PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN );/* probably unused */
	
		PORT_START(); 	/* IN2 */
		PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_COCKTAIL );
		PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT | IPF_8WAY | IPF_COCKTAIL );
		PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN | IPF_8WAY | IPF_COCKTAIL );
		PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_UP | IPF_8WAY | IPF_COCKTAIL );
		PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_COCKTAIL );
		PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_COCKTAIL );
		PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN );/* probably unused */
		PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN );/* probably unused */
	
		PORT_START(); 	/* DSW0 */
		PORT_DIPNAME( 0x07, 0x07, "Coin A", IP_KEY_NONE );
		PORT_DIPSETTING(    0x01, "4 Coins/1 Credit" );
		PORT_DIPSETTING(    0x02, "3 Coins/1 Credit" );
		PORT_DIPSETTING(    0x04, "2 Coins/1 Credit" );
		PORT_DIPSETTING(    0x07, "1 Coin/1 Credit" );
		PORT_DIPSETTING(    0x03, "2 Coins/3 Credits" );
		PORT_DIPSETTING(    0x06, "1 Coin/2 Credits" );
		PORT_DIPSETTING(    0x05, "1 Coin/4 Credits" );
		PORT_DIPSETTING(    0x00, "Free Play" );
		PORT_DIPNAME( 0x08, 0x00, "Cabinet", IP_KEY_NONE );
		PORT_DIPSETTING(    0x00, "Upright" );
		PORT_DIPSETTING(    0x08, "Cocktail" );
		PORT_DIPNAME( 0x30, 0x30, "Bonus Life", IP_KEY_NONE );
		PORT_DIPSETTING(    0x30, "20000 80000" );
		PORT_DIPSETTING(    0x20, "20000 100000" );
		PORT_DIPSETTING(    0x10, "30000 80000" );
		PORT_DIPSETTING(    0x00, "30000 100000" );
		PORT_DIPNAME( 0xc0, 0xc0, "Lives", IP_KEY_NONE );
		PORT_DIPSETTING(    0x80, "1" );
		PORT_DIPSETTING(    0x40, "2" );
		PORT_DIPSETTING(    0xc0, "3" );
		PORT_DIPSETTING(    0x00, "5" );
	
		PORT_START(); 	/* DSW1 */
		PORT_DIPNAME( 0x07, 0x07, "Coin B", IP_KEY_NONE );
		PORT_DIPSETTING(    0x01, "4 Coins/1 Credit" );
		PORT_DIPSETTING(    0x02, "3 Coins/1 Credit" );
		PORT_DIPSETTING(    0x04, "2 Coins/1 Credit" );
		PORT_DIPSETTING(    0x07, "1 Coin/1 Credit" );
		PORT_DIPSETTING(    0x03, "2 Coins/3 Credits" );
		PORT_DIPSETTING(    0x06, "1 Coin/2 Credits" );
		PORT_DIPSETTING(    0x05, "1 Coin/4 Credits" );
		PORT_DIPSETTING(    0x00, "Free Play" );
		PORT_BITX(    0x08, 0x08, IPT_DIPSWITCH_NAME | IPF_TOGGLE, "Service Mode", OSD_KEY_F2, IP_JOY_NONE, 0 );
		PORT_DIPSETTING(    0x08, "Off" );
		PORT_DIPSETTING(    0x00, "On" );
		PORT_DIPNAME( 0x10, 0x10, "Flip Screen", IP_KEY_NONE );
		PORT_DIPSETTING(    0x10, "Off" );
		PORT_DIPSETTING(    0x00, "On" );
		PORT_DIPNAME( 0x60, 0x60, "Difficulty", IP_KEY_NONE );
		PORT_DIPSETTING(    0x40, "Easy" );
		PORT_DIPSETTING(    0x60, "Normal" );
		PORT_DIPSETTING(    0x20, "Hard" );
		PORT_DIPSETTING(    0x00, "Hardest" );
		PORT_DIPNAME( 0x80, 0x80, "Freeze", IP_KEY_NONE );
		PORT_DIPSETTING(    0x80, "Off" );
		PORT_DIPSETTING(    0x00, "On" );
	INPUT_PORTS_END(); }}; 



	static GfxLayout charlayout = new GfxLayout
	(
				8,8,	/* 8*8 characters */
		512,	/* 512 characters */
		2,	/* 2 bits per pixel */
		new int[]{ 4, 0 },
		new int[]{ 0, 1, 2, 3, 8+0, 8+1, 8+2, 8+3 },
		new int[]{ 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16 },
		16*8	/* every char takes 16 consecutive bytes */
	);
	static GfxLayout tilelayout = new GfxLayout
	(
		16,16,	/* 16*16 tiles */
		512,	/* 512 tiles */
		3,	/* 3 bits per pixel */
		new int[]{ 0, 512*32*8, 2*512*32*8 },	/* the bitplanes are separated */
		new int[]{ 0, 1, 2, 3, 4, 5, 6, 7,
				16*8+0, 16*8+1, 16*8+2, 16*8+3, 16*8+4, 16*8+5, 16*8+6, 16*8+7 },
		new int[]{ 0*8, 1*8, 2*8, 3*8, 4*8, 5*8, 6*8, 7*8,
				8*8, 9*8, 10*8, 11*8, 12*8, 13*8, 14*8, 15*8 },
		32*8	/* every tile takes 32 consecutive bytes */
	);
	static GfxLayout spritelayout = new GfxLayout
	(
		16,16,	/* 16*16 sprites */
		512,	/* 512 sprites */
		4,	/* 4 bits per pixel */
		new int[]{ 512*64*8+4, 512*64*8+0, 4, 0 },
		new int[]{ 0, 1, 2, 3, 8+0, 8+1, 8+2, 8+3,
				32*8+0, 32*8+1, 32*8+2, 32*8+3, 33*8+0, 33*8+1, 33*8+2, 33*8+3 },
		new int[]{ 0*16, 1*16, 2*16, 3*16, 4*16, 5*16, 6*16, 7*16,
				8*16, 9*16, 10*16, 11*16, 12*16, 13*16, 14*16, 15*16 },
		64*8	/* every sprite takes 64 consecutive bytes */
	);



	static GfxDecodeInfo gfxdecodeinfo[] =
	{
		new GfxDecodeInfo( 1, 0x00000, charlayout,             0, 64 ),
		new GfxDecodeInfo( 1, 0x02000, tilelayout,          64*4, 4*32 ),
		new GfxDecodeInfo( 1, 0x0e000, spritelayout, 64*4+4*32*8, 16 ),
		new GfxDecodeInfo( -1 ) /* end of array */
	};



	/* these are NOT the original color PROMs */
	static char color_prom[] =
	{
		/* 08E_SB-5: palette red component */
		0x00,0x00,0x00,0x04,0x06,0x07,0x00,0x08,0x05,0x00,0x08,0x00,0x07,0x00,0x00,0x00,
		0x00,0x00,0x00,0x04,0x06,0x07,0x00,0x08,0x05,0x06,0x08,0x07,0x00,0x05,0x00,0x00,
		0x00,0x09,0x08,0x06,0x05,0x04,0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x07,0x06,0x07,0x00,0x08,0x05,0x06,0x08,0x00,0x07,0x00,0x00,0x00,
		0x00,0x0B,0x09,0x07,0x05,0x03,0x0C,0x0A,0x08,0x06,0x04,0x0E,0x0E,0x0D,0x07,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x08,0x05,0x0B,0x0A,0x0A,0x0B,0x0C,0x0C,0x0E,0x0C,0x00,0x03,0x04,0x06,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x08,0x05,0x0B,0x0A,0x0A,0x0B,0x0C,0x0C,0x0E,0x0C,0x00,0x03,0x04,0x06,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		/* 09E_SB-6: palette green component */
		0x00,0x05,0x08,0x06,0x05,0x06,0x07,0x08,0x04,0x05,0x07,0x07,0x07,0x06,0x05,0x06,
		0x00,0x05,0x08,0x06,0x05,0x06,0x07,0x08,0x05,0x06,0x07,0x07,0x04,0x06,0x05,0x06,
		0x00,0x09,0x08,0x07,0x06,0x05,0x06,0x07,0x05,0x06,0x04,0x00,0x00,0x00,0x05,0x06,
		0x00,0x05,0x08,0x06,0x05,0x06,0x07,0x08,0x04,0x05,0x07,0x07,0x07,0x06,0x05,0x06,
		0x00,0x0E,0x0C,0x0A,0x07,0x05,0x0C,0x0A,0x08,0x06,0x04,0x0C,0x09,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x0A,0x09,0x0B,0x05,0x09,0x00,0x05,0x09,0x0E,0x0C,0x0A,0x0D,0x06,0x0A,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x0A,0x09,0x0B,0x05,0x09,0x00,0x05,0x09,0x0E,0x0C,0x0A,0x0D,0x06,0x0A,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		/* 10E_SB-7: palette blue component */
		0x00,0x00,0x00,0x00,0x04,0x05,0x00,0x08,0x03,0x00,0x06,0x08,0x07,0x07,0x08,0x09,
		0x00,0x00,0x00,0x00,0x04,0x05,0x00,0x08,0x05,0x06,0x06,0x07,0x05,0x06,0x08,0x09,
		0x00,0x09,0x08,0x07,0x06,0x05,0x05,0x06,0x08,0x09,0x07,0x00,0x00,0x00,0x08,0x09,
		0x00,0x00,0x00,0x05,0x04,0x05,0x00,0x08,0x03,0x04,0x06,0x08,0x07,0x07,0x08,0x09,
		0x00,0x00,0x00,0x00,0x00,0x00,0x09,0x07,0x05,0x03,0x01,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x0D,0x0B,0x0B,0x08,0x0F,0x00,0x00,0x00,0x0E,0x00,0x00,0x0B,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x0D,0x0B,0x0B,0x08,0x0F,0x00,0x00,0x00,0x0E,0x00,0x00,0x0B,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
		/* F01_SB-0: char lookup table */
		0x0F,0x01,0x02,0x03,0x0F,0x02,0x03,0x04,0x0F,0x03,0x04,0x05,0x0F,0x04,0x05,0x06,
		0x0F,0x05,0x06,0x07,0x0F,0x06,0x07,0x08,0x0F,0x07,0x08,0x09,0x0F,0x08,0x09,0x0A,
		0x0F,0x09,0x0A,0x0B,0x0F,0x0A,0x0B,0x0C,0x0F,0x0B,0x0C,0x0D,0x0F,0x0C,0x0D,0x0E,
		0x0F,0x0D,0x0E,0x0F,0x0F,0x0E,0x0F,0x01,0x0F,0x0F,0x01,0x02,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x00,0x00,0x00,0x0F,0x01,0x01,0x01,0x0F,0x02,0x02,0x02,0x0F,0x03,0x03,0x03,
		0x0F,0x04,0x04,0x04,0x0F,0x05,0x05,0x05,0x0F,0x06,0x06,0x06,0x0F,0x07,0x07,0x07,
		0x0F,0x08,0x08,0x08,0x0F,0x09,0x09,0x09,0x0F,0x0A,0x0A,0x0A,0x0F,0x0B,0x0B,0x0B,
		0x0F,0x0C,0x0C,0x0C,0x0F,0x0D,0x0D,0x0D,0x0F,0x0E,0x0E,0x0E,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x03,0x01,0x04,0x0F,0x04,0x03,0x05,0x0F,0x05,0x04,0x06,0x0F,0x06,0x05,0x07,
		0x0F,0x07,0x06,0x08,0x0F,0x08,0x07,0x0A,0x0F,0x0A,0x08,0x0B,0x0F,0x0B,0x0A,0x0E,
		0x0F,0x0E,0x0B,0x0D,0x0F,0x0D,0x0E,0x0C,0x0F,0x0C,0x0D,0x09,0x0F,0x09,0x0C,0x02,
		0x0F,0x02,0x09,0x01,0x0F,0x01,0x02,0x03,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x09,0x0D,0x0E,0x0F,0x04,0x0D,0x0A,0x0F,0x01,0x02,0x09,0x0F,0x01,0x00,0x03,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x09,0x09,0x09,0x0F,0x0A,0x0A,0x0A,0x0F,0x0A,0x06,0x02,0x0F,0x0C,0x0F,0x0F,
		/* 06D_SB-4: tile lookup table */
		0x00,0x01,0x02,0x03,0x04,0x05,0x08,0x0A,0x00,0x01,0x07,0x0C,0x04,0x05,0x0E,0x0F,
		0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x0A,0x00,0x01,0x0D,0x03,0x04,0x0E,0x09,0x0F,
		0x00,0x01,0x0A,0x03,0x04,0x05,0x06,0x08,0x00,0x01,0x02,0x0E,0x0F,0x05,0x06,0x07,
		0x00,0x01,0x08,0x03,0x0B,0x0E,0x06,0x0F,0x00,0x01,0x07,0x0B,0x09,0x0E,0x0D,0x0F,
		0x00,0x01,0x0F,0x0C,0x04,0x05,0x06,0x07,0x00,0x01,0x0A,0x0F,0x04,0x0E,0x06,0x07,
		0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x09,0x00,0x0A,0x02,0x09,0x08,0x05,0x06,0x07,
		0x00,0x08,0x0A,0x03,0x04,0x05,0x0D,0x0B,0x00,0x01,0x02,0x03,0x0C,0x05,0x06,0x0D,
		0x00,0x01,0x02,0x03,0x05,0x08,0x09,0x0A,0x00,0x08,0x02,0x09,0x04,0x05,0x06,0x07,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x00,0x0D,0x08,0x09,0x0A,0x0B,0x0C,0x0E,
		/* 03K_SB-8: sprite lookup table */
		0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x06,0x08,0x0D,0x0E,0x0F,
		0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x08,0x06,0x0D,0x0E,0x0F,
		0x00,0x06,0x07,0x08,0x09,0x0A,0x06,0x07,0x08,0x09,0x0A,0x06,0x08,0x0D,0x0E,0x0F,
		0x00,0x06,0x07,0x08,0x09,0x0A,0x06,0x07,0x08,0x09,0x0A,0x08,0x06,0x0D,0x0E,0x0F,
		0x00,0x0B,0x0C,0x0D,0x0E,0x0E,0x06,0x07,0x08,0x09,0x0A,0x06,0x08,0x0D,0x0E,0x0F,
		0x00,0x0B,0x0C,0x0D,0x0E,0x0E,0x06,0x07,0x08,0x09,0x0A,0x08,0x06,0x0D,0x0E,0x0F,
		0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
		0x00,0x06,0x07,0x08,0x09,0x0A,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,
		0x00,0x06,0x08,0x09,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
		0x00,0x08,0x06,0x09,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
	};



	static MachineDriver machine_driver = new MachineDriver
	(
		/* basic machine hardware */
		new MachineCPU[] {
			new MachineCPU(
				CPU_Z80,
				4000000,	/* 4 Mhz (?) */
				0,
				readmem, writemem, null, null,
				c1942_interrupt, 2
			),
			new MachineCPU(
				CPU_Z80,
				3000000,	/* 3 Mhz ??? */
				2,	/* memory region #2 */
				sound_readmem, sound_writemem, null, null,
				capcom_sh_interrupt,12
			)
		},
		60,
		null,

		/* video hardware */
		32*8, 32*8, new rectangle( 0*8, 32*8-1, 2*8, 30*8-1  ),
		gfxdecodeinfo,
		256,64*4+4*32*8+16*16,
		c1942_vh_convert_color_prom,
                VIDEO_TYPE_RASTER,
		null,
		c1942_vh_start,
		c1942_vh_stop,
		c1942_vh_screenrefresh,

		/* sound hardware */
		null,
		null,
		capcom_sh_start,
		AY8910_sh_stop,
		AY8910_sh_update
	);


	/***************************************************************************

	  Game driver(s)

	***************************************************************************/

	static RomLoadPtr c1942_rom = new RomLoadPtr(){ public void handler(){ 
		ROM_REGION(0x1c000);/* 64k for code + 3*16k for the banked ROMs images */
		ROM_LOAD( "1-n3a.bin",  0x0000, 0x4000, 0x33ff9663 );
		ROM_LOAD( "1-n4.bin",  0x4000, 0x4000, 0xd492925e );
		ROM_LOAD( "1-n7.bin",  0x8000, 0x4000, 0xc9728db2 );/* this is the only one of the banked ROMs containing code */
		ROM_LOAD( "1-n5.bin", 0x10000, 0x4000, 0xf2525fe2 );
		ROM_LOAD( "1-n6.bin", 0x14000, 0x2000, 0x659736b3 );
		ROM_LOAD( "1-n7.bin", 0x18000, 0x4000, 0xc9728db2 );
	
		ROM_REGION(0x1e000);/* temporary space for graphics (disposed after conversion) */
		ROM_LOAD( "1-f2.bin", 0x00000, 0x2000, 0x90e7df87 );/* characters */
		ROM_LOAD( "2-a1.bin", 0x02000, 0x2000, 0x144b5325 );/* tiles */
		ROM_LOAD( "2-a2.bin", 0x04000, 0x2000, 0xbeecefb2 );
		ROM_LOAD( "2-a3.bin", 0x06000, 0x2000, 0x6649e7e3 );
		ROM_LOAD( "2-a4.bin", 0x08000, 0x2000, 0x33e7a52d );
		ROM_LOAD( "2-a5.bin", 0x0a000, 0x2000, 0x606bfaa1 );
		ROM_LOAD( "2-a6.bin", 0x0c000, 0x2000, 0xcb9343fd );
		ROM_LOAD( "2-l1.bin", 0x0e000, 0x4000, 0x3de5e617 );/* sprites */
		ROM_LOAD( "2-l2.bin", 0x12000, 0x4000, 0x900c4178 );
		ROM_LOAD( "2-n1.bin", 0x16000, 0x4000, 0x8b02cefe );
		ROM_LOAD( "2-n2.bin", 0x1a000, 0x4000, 0x0fb73451 );
	
		ROM_REGION(0x10000);/* 64k for the audio CPU */
		ROM_LOAD( "1-c11.bin", 0x0000, 0x4000, 0xb16cd20e );
	ROM_END(); }}; 


	static HiscoreLoadPtr hiload = new HiscoreLoadPtr() { public int handler(String name)
	{
		/* get RAM pointer (this game is multiCPU, we can't assume the global */
		/* RAM pointer is pointing to the right place) */
		char []RAM = Machine.memory_region[0];


		/* check if the hi score table has already been initialized */
		if (memcmp(RAM, 0xe801, new char[] { 0x00, 0x04, 0x00, 0x00 }, 4) == 0 &&
				memcmp(RAM, 0xe981, new char[] { 0x00, 0x00, 0x01, 0x00 }, 4) == 0)
		{
			FILE f;


			if ((f = fopen(name, "rb")) != null)
			{
				int i;


				fread(RAM, 0xe800, 1, 16*25, f);
				fread(RAM, 0xe9c0, 1, 1, f);
				/* find the high score */
				for (i = 0; i < 16*25; i += 16)
				{
					if (RAM[0xe800 + i] == 0x00)
					{
						RAM[0xe040] = (char) (RAM[0xe801 + i] >> 4);
						RAM[0xe041] = (char) (RAM[0xe801 + i] & 0x0f);
						RAM[0xe042] = (char) (RAM[0xe802 + i] >> 4);
						RAM[0xe043] = (char) (RAM[0xe802 + i] & 0x0f);
						RAM[0xe044] = (char) (RAM[0xe803 + i] >> 4);
						RAM[0xe045] = (char) (RAM[0xe803 + i] & 0x0f);
						RAM[0xe046] = (char) (RAM[0xe804 + i] >> 4);
						RAM[0xe047] = (char) (RAM[0xe804 + i] & 0x0f);

						break;
					}
				}
				fclose(f);
			}

			return 1;
		}
		else return 0;	/* we can't load the hi scores yet */
	} };



	static HiscoreSavePtr hisave = new HiscoreSavePtr() { public void handler(String name)
	{
		FILE f;
		/* get RAM pointer (this game is multiCPU, we can't assume the global */
		/* RAM pointer is pointing to the right place) */
		char []RAM = Machine.memory_region[0];


		if ((f = fopen(name, "wb")) != null)
		{
			fwrite(RAM, 0xe800, 1, 16*25, f);
			fwrite(RAM, 0xe9c0, 1, 1, f);
			fclose(f);
		}
	} };


         public static GameDriver c1942_driver = new GameDriver
        (
            "1942",
            "1942",
            "Paul Leaman (hardware info)\nNicola Salmoria (MAME driver)",
            machine_driver,

            c1942_rom,
            null, null,
            null,

            null/*TBR*/,input_ports,null/*TBR*/,null/*TBR*/,null/*TBR*/,

            color_prom, null, null,
            ORIENTATION_ROTATE_270,

            hiload, hisave
         );

}
